//
//  WYMomentVideoView.m
//  FriendCircleDemo
//
//  Created by mac on 2018/10/10.
//  Copyright © 2018年 WY. All rights reserved.
//

#import "WYMomentVideoView.h"

@interface WYMomentVideoView ()

/// coverView
@property (nonatomic, readwrite, weak) UIImageView *coverView;

/// playBtn
@property (nonatomic, readwrite, weak) UIButton *playBtn;

@end

@implementation WYMomentVideoView

+ (instancetype)videoView{
    return [[self alloc] init];
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        // 创建自控制器
        [self setupSubViews];
        
        // 布局子控件
        [self makeSubViewsConstraints];
    }
    return self;
}

#pragma mark - 初始化子控件
- (void)setupSubViews{
    /// avatarView
    UIImageView *coverView = [[UIImageView alloc] init];
    coverView.userInteractionEnabled = YES;
    self.coverView = coverView;
    [self addSubview:coverView];
    
    
    /// 播放按钮
    
    UIButton *playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [playBtn setImage:[UIImage imageNamed:@"Fav_List_Video_Play_40x40"] forState:UIControlStateNormal];
    [playBtn setImage:[UIImage imageNamed:@"Fav_List_Video_Play_HL_40x40"] forState:UIControlStateHighlighted];
    self.playBtn = playBtn;
    [coverView addSubview:playBtn];
}

#pragma mark - 布局子控件
- (void)makeSubViewsConstraints{
    [self.coverView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsZero);
    }];
    
    [self.playBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsZero);
    }];
}

-(void)setItemViewModel:(WYMomentItemViewModel *)itemViewModel
{
    _itemViewModel = itemViewModel;
    WYMomentVideo *videoInfo = itemViewModel.moment.videoInfo;
    self.coverView.image = videoInfo.coverImage;
}
@end
